/*
 * dislegend.js
 * 闪电图例
 */
;
(function (call) {
    var main = {
        baseUrl: CafeJS.CXT,
        mapId: "tjMap",
        init: function () {
            this.initView();
        },
        initView: function () {
            var that = this;
            var $body = $("#ListInfoTable tbody").empty();
            var curTime = $("#datepicker-light .datepicker-date span").text();
            var startTime = new Date(curTime);
            startTime = startTime.setHours(startTime.getHours() - 24);
            var timeArr = that.getProcessHours(new Date(startTime), new Date(curTime));
            timeArr = $.grep(timeArr, function (n, i) {
                if (i != 0) {
                    return i % 3 == 0;
                }
            })
            var tr = '';
            for (var i = 0; i < timeArr.length; i++) {
                var index = i + 1;
                var date = new Date(timeArr[i]);
                date.setHours(date.getHours() - 3);
                tr += '<tr><td><span class="light_colorIco" proid="colorIco_0' + index + '">';
                tr += '<div class="light_colorImg" style="background-image: url(business/skgc/css/images/colorIco_0' + index + '.png);"></div></span></td>'
                tr += '<td><span class="light_colorIco colorText color_' + index + ' active" proid="' + timeArr[i] + '">'
                tr += new Date(date).format('dd hh') + ' - - ' + new Date(timeArr[i]).format('dd hh') + '</span>';
                tr += '</td></tr>';
            }
            $body.append(tr);
        },
        // 获取开始结束区间内每个小时
        getProcessTime: function (time) {
            let ymd = '';
            let mouth = (time.getMonth() + 1) >= 10 ? (time.getMonth() + 1) : ('0' + (time.getMonth() + 1));
            let day = time.getDate() >= 10 ? time.getDate() : ('0' + time.getDate());
            let hours = time.getHours() >= 10 ? time.getHours() : ('0' + time.getHours());
            ymd += time.getFullYear() + '-';
            ymd += mouth + '-';
            ymd += day;
            ymd += ' ' + hours + ':00';
            return ymd;
        },
        getProcessHours: function (start, end) {
            var dateArr = [];
            let ubixDb = new Date(start).getTime();
            let ubixDe = new Date(end).getTime();
            let stamp;
            const oneHours = 60 * 60 * 1000;
            for (stamp = ubixDb; stamp <= ubixDe;) {
                dateArr.push(this.getProcessTime(new Date(parseInt(stamp))));
                stamp = stamp + oneHours;
            }
            return dateArr;
        },
    };
    if (typeof call === 'function') {
        CafeJS.dislegend = main;
        call(main);
    }

})(function (main) {
    CafeJS.models(['datepicker', 'legentpicker', 'legentconfig', 'ajax', 'timeLine3'], function () {
        main.init();
    });
});
